import com.demo.component.UserComponent;
import com.demo.controller.StudentController;
import com.demo.controller.UserAdviceController;
import com.demo.controller.UserController;
import com.demo.model.Student;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * @author vivi
 * @description
 * @date 2024/5/19
 */
public class App {
    public static void main (String[] args) {
//        // BeanFactory 懒汉模式
//        // ApplicationContext 饿汉模式
////        BeanFactory context = new
////                XmlBeanFactory(new ClassPathResource("spring-config.xml"));
////        System.out.println("BeanFactory 之后的代码");
//        // 1 先得到Spring对象
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        System.out.println("ApplicationContext 之后的代码");
//        // 2 从Spring中取出Bean对象
//        // 根据名称
////        User user = (User) context.getBean("user");
//        // 根据 Bean名称 和 Bean类型
//        User user = context.getBean("user", User.class);
//        // 3 使用Bean
//        System.out.println(user.sayHai());

        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");

//        BeanFactory context = new
//                XmlBeanFactory(new ClassPathResource("spring-config.xml"));

//        ArticleController articleController = context.getBean("articleController", ArticleController.class);
//        articleController.show();

//        UserComponent component = context.getBean("userComponent", UserComponent.class);
//        component.show();

//        User user = context.getBean("user", User.class);
//        user.sayHai();

//        Student student = context.getBean("student", Student.class);
//        System.out.println(student);

//        StudentController studentController = context.getBean("studentController", StudentController.class);
//        studentController.show();

        UserController userController = context.getBean("userController", UserController.class);
        userController.getUser();;

        UserAdviceController userAdviceController = context.getBean("userAdviceController", UserAdviceController.class);
        userAdviceController.getUser();
    }
}













